<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\AdminBaseController;
use think\Db;



class AdminNoticeSortController extends AdminBaseController
{
    //列表
    public function index(){
        
        $log_list = Db::name('notice_sort')->select();
  
        $this->assign("data", $log_list);
        return $this->fetch();
    }

    //编辑
    public function edit(){
        $id = $this->request->param('id', 0, 'intval');
        $data = Db::name('notice_sort')->find($id);
        $this->assign('result',$data);
        return $this->fetch();
    }
    //编辑提交
    public function editPost(){
        if ($this->request->isPost()) {
            $post   = $this->request->param();
            
            if (empty($post['name'])) {
                $this->error("分类名称不能为空！");
            }
            
            $res = Db::name('notice_sort')->where(['id'=>$post['id']])->update($post);
            if ($res) {
                //操作日志
                admin_log($post['name'], 'edit', '公告动态文章');

                $this->success('编辑成功!', url('AdminNoticeSort/index'));
            }else{
                $this->error('编辑失败');
            }
            
        }
    }

}
